from flask import Flask,render_template,request,url_for,redirect
from werkzeug.utils import secure_filename
import os
import time

app=Flask(__name__)

@app.route('/upload',methods=['GET','POST'])
def upload():
    if request.method =='POST':
        f=request.files.get('file')
        filename=f.filename.split('.')
        time_str=''.join(str(time.strftime('%y/%m/%d %H:%M:%S')).split('.'))
        filename=filename[0]+time_str+'.'+filename[-1]
        basepath=os.path.dirname(__file__)
        upload_path=os.path.join(basepath,'static/file/')
        file_name=upload_path+secure_filename(filename)
        print(file_name)
        f.save(file_name)
        return 'ok'
    return render_template('upload.html')


if __name__=='__main__':
    app.run(debug=True)